<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.yuxin.common.util.*" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.util.*" %>
<%@ page import="com.yuxin.core.TransactionManager" %>
<%@ page import="com.yuxin.core.exception.BusinessException" %>

<%
    String action = request.getParameter("action");
    String orderId = request.getParameter("id");
    Connection conn = null;
    TransactionManager tranM = null;
    Map result = new HashMap();
    response.setContentType("text/html;charset=UTF-8");
	try {		
		if(action != null && orderId != null) {
			conn = DBUtil.getConnection();
			tranM = new TransactionManager(conn);
			
			int res = -1;
			if("confirm_fahuo".equals(action)) {
				tranM.begin();
				String sql = "update p_orders set STATUS = 3, SHIPPING_TIME = ? where ID = ? and status = 2";
				res = DBUtil.executeSql(conn, sql, new Object[]{new Date(), orderId});				
			} else if("confirm_tkuan".equals(action)) { // Close order
				tranM.begin();
				String sql = "update p_orders set STATUS = 6 where ID = ? and status = 4";
				res = DBUtil.executeSql(conn, sql, orderId);
			}
			if(res > 0) {
				result.put("isSuccess",true);
			}
		}
	} catch (Exception ex) {
		if(tranM != null) {
			tranM.rollback();
		}
		ex.printStackTrace();
		result.put("isSuccess",false);
	    result.put("error",ex.getMessage());
	} finally {
		if(tranM != null) {
			tranM.commit();
		}
		DBUtil.close(conn);
		response.getWriter().write(JsonUtil.convertString(result));
        out.clear();
        out = pageContext.pushBody();
	}
%>